import 'package:animated_bottom_navigation_bar/animated_bottom_navigation_bar.dart';
import 'package:flutter/services.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/modules/home/controller.dart';

class HomePage extends StatelessWidget {
  HomePage({super.key});

  final controller = Get.put(HomeController());

  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: false,
      onPopInvoked: (bool isPop) {
        final bool pop = controller.exitReminder();
        if (pop) {
          SystemChannels.platform.invokeMethod('SystemNavigator.pop');
        }
      },
      child: GetBuilder(builder: (HomeController controller) {
        return Scaffold(
            backgroundColor: Colors.white,
            extendBody: true,
            body: IndexedStack(
              index: controller.index.value,
              children: controller.myTabs,
            ),
            floatingActionButtonLocation:
                FloatingActionButtonLocation.centerDocked,
            floatingActionButton: FloatingActionButton(
              shape: const CircleBorder(),
              backgroundColor: Colors.transparent,
              onPressed: controller.jumpToSnap,
              // child: SvgPicture.asset(
              //   'assets/svg/icon_yinhuan_center.svg',
              //   width: 55.w,
              //   height:55.w,
              // ),
              child: Container(
                width: 55.w,
                height: 55.w,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(26.w),
                    gradient: const LinearGradient(
                      begin: Alignment.topLeft,
                      end: Alignment.bottomRight,
                      colors: [
                        Color(0xFF54B7FD),
                        Color(0xFF1EA2FF),
                        Color(0xFF1847E3),
                      ],
                    )),
                child: const Icon(
                  Icons.photo_camera_rounded,
                  color: Colors.white,
                ),
              ),
            ),
            bottomNavigationBar: AnimatedBottomNavigationBar.builder(
              itemCount: controller.tabName.length,
              activeIndex: controller.index.value,
              tabBuilder: (int index, bool isActive) {
                final color = isActive ? const Color(0xFF5C6DFF) : Colors.black;
                final icon = isActive
                    ? controller.tabIcon[index]
                    : controller.tabCancel[index];
                return Column(
                  mainAxisSize: MainAxisSize.min,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    SvgPicture.asset(icon),
                    const SizedBox(height: 4),
                    Padding(
                      padding: EdgeInsets.symmetric(horizontal: 8.w),
                      child: Text(
                        controller.tabName[index],
                        maxLines: 1,
                        style: TextStyle(color: color, fontSize: 10.sp),
                      ),
                    )
                  ],
                );
              },
              splashSpeedInMilliseconds: 300,
              notchSmoothness: NotchSmoothness.softEdge,
              gapLocation: GapLocation.center,
              // leftCornerRadius: 32,
              // rightCornerRadius: 32,
              shadow: const BoxShadow(
                offset: Offset(0, 0.3),
                color: Colors.black12,
                blurRadius: 8,
                spreadRadius: 0.6,
              ),
              onTap: (index) {
                controller.index.value = index;
                controller.update();
              },
            ));
      }),
    );
  }
}
